package com.example.orderprovider.provider;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.UUID;

@RestController
@RequestMapping("provider")
public class OrderProviderController {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/makeOrder")
    public String makeOrder() {
        String orderId = String.valueOf(UUID.randomUUID()); // 生成随机订单号
        String orderInfo = "迈巴赫 S480";
        HashMap<String, String> orderMap = new HashMap<>();
        orderMap.put("orderId", orderId);
        orderMap.put("orderInfo", orderInfo);
        rabbitTemplate.convertAndSend("order_exchange","orderRouting",orderMap);
        System.out.println("付款中...");
        return "<p style=color:blue;text-align:center;top:20px;font-size:28px;>下单成功，订单号为："+orderId+"</p>";
    }
}
